package espace_physique;

import fichiers.Element;
import fichiers.RacineDossier;
import fichiers.RacinePicasial;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import javax.swing.filechooser.FileSystemView;
import javax.swing.tree.*;

public class MyDefaultTreeCellRendererPicasial extends DefaultTreeCellRenderer{
    
    private static ImageIcon iconElement;
    private static ImageIcon pdt=new ImageIcon("pdt.jpg");
    private static ImageIcon imSuppr=new ImageIcon("imageSupprime.jpg");    
    private static JFileChooser jf=new JFileChooser();
    private TreeCellRenderer next;

    
    public MyDefaultTreeCellRendererPicasial(TreeCellRenderer next) {
    
        this.next=next;
    }
    
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        
        DefaultMutableTreeNode t=(DefaultMutableTreeNode)value;
        Element f=(Element)t.getUserObject();
        File fichier=f.getFichierCourant();
        JLabel valeurLabel=(JLabel) next.getTreeCellRendererComponent(tree,value,sel,expanded,leaf,row,hasFocus);

        if(fichier!=null && fichier.exists()){
            iconElement=(ImageIcon) jf.getFileSystemView().getSystemIcon(fichier);
            valeurLabel.setIcon(this.iconElement);
        } else if(f==RacinePicasial.getRacine() || f==RacineDossier.getRacine()){
            valeurLabel.setIcon(pdt);
        }
        else{
            valeurLabel.setIcon(imSuppr);           
        }
              
               
        return valeurLabel;
    }
    
    
}
